package com.uobgroup.ews.uam.core.domain;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.OneToOne;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import org.springframework.beans.factory.annotation.Configurable;

@Entity
@Configurable
public class UAMRole extends BaseEntity implements SecurityGroupAware {

   @NotNull
   @Size(max = 64)
   private String name;

   @Size(max = 1000)
   private String description;

   @OneToOne(cascade = CascadeType.PERSIST)
   private SecurityGroup securityGroup;

   //
   @OneToOne
   private RoleSubType roleSubType;

   @OneToOne
   private Reference roleType;

   @OneToOne
   private Reference processingCentre;

   @OneToOne
   private Reference department;

   @ManyToMany(fetch = FetchType.LAZY, mappedBy = "roles", cascade = { CascadeType.PERSIST, CascadeType.MERGE,
         CascadeType.REFRESH })
   private List<Profile> profiles;

   @Id
   @GeneratedValue(strategy = GenerationType.AUTO)
   @Column(name = "id")
   private Long id;

   @Column(name = "IsAdmin", nullable = false, columnDefinition = "boolean default false")
   private Boolean isAdmin;

   /**
    * @return the isAdmin
    */
   public Boolean getIsAdmin() {
      return isAdmin;
   }

   /**
    * @param isAdmin
    *           the isAdmin to set
    */
   public void setIsAdmin(Boolean isAdmin) {
      this.isAdmin = isAdmin;
   }

   public Long getId() {
      return this.id;
   }

   public void setId(Long id) {
      this.id = id;
   }

   public String getName() {
      return this.name;
   }

   public void setName(String name) {
      this.name = name;
   }

   public String getDescription() {
      return this.description;
   }

   public void setDescription(String description) {
      this.description = description;
   }

   public SecurityGroup getSecurityGroup() {
      return this.securityGroup;
   }

   public void setSecurityGroup(SecurityGroup securityGroup) {
      this.securityGroup = securityGroup;
   }

   public Reference getRoleType() {
      return this.roleType;
   }

   public void setRoleType(Reference roleType) {
      this.roleType = roleType;
   }

   public Reference getProcessingCentre() {
      return this.processingCentre;
   }

   public void setProcessingCentre(Reference processingCentre) {
      this.processingCentre = processingCentre;
   }

   public Reference getDepartment() {
      return this.department;
   }

   public void setDepartment(Reference department) {
      this.department = department;
   }

   public RoleSubType getRoleSubType() {
      return roleSubType;
   }

   public void setRoleSubType(RoleSubType roleSubType) {
      this.roleSubType = roleSubType;
   }

   public List<Profile> getProfiles() {
      return profiles;
   }

   public void setProfiles(List<Profile> profiles) {
      this.profiles = profiles;
   }

   @Override
   public String getSecurityGroupName() {
      return name;
   }

   @Override
   public String getParentGroupName() {
      return "roles";
   }

}